﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;
using System.Reflection;




namespace DotNetNuke.Tests.UI.WatiN.HostTests
{
    [TestFixture]
    
    public class HostAccountsTests : HTBase
    {
        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {
            
            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            TearDownTest();
        }

        #endregion

        #region Tests


        [Test]
        public void Add_Host_User()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Act
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            HostUserPage hostUserPage = new HostUserPage(homePage);
            hostUserPage.AddNewUserStartLink.Click();
            //Enter User inforrmation
            hostUserPage.UserNameField.Value = TestUsers.TestHost.UserName;
            hostUserPage.FirstNameField.Value = TestUsers.TestHost.FirstName;
            hostUserPage.LastNameField.Value = TestUsers.TestHost.LastName;
            hostUserPage.DisplayNameField.Value = TestUsers.TestHost.DisplayName;
            hostUserPage.EmailField.Value = TestUsers.TestHost.EmailAddress;
            hostUserPage.PasswordField.Value = TestUsers.TestHost.Password;
            hostUserPage.ConfirmPasswordField.Value = TestUsers.TestHost.Password;
            hostUserPage.AddNewUserLink.ClickNoWait();

            //Assert
            System.Threading.Thread.Sleep(2500);
            TableCell userNameCell = hostUserPage.GetUserRow(TestUsers.TestHost.DisplayName).TableCells[5];
            Assert.IsTrue(userNameCell.InnerHtml.Contains(TestUsers.TestHost.UserName));
            //Log off the host
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            //Attempt to log the new host user in
            loginPage.LoginUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password);
            Assert.IsTrue(loginPage.RegisterLink.Text.StartsWith(TestUsers.TestHost.DisplayName));
        }

        [Test]
        public void Unauthorize_Host_User()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            HostUserPage hostUserPage = new HostUserPage(homePage);

            //Add Host User for Testing
            hostUserPage.AddUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password, TestUsers.TestHost.FirstName, TestUsers.TestHost.LastName, TestUsers.TestHost.EmailAddress, TestUsers.TestHost.DisplayName);
            System.Threading.Thread.Sleep(2000);

            //Act
            hostUserPage.GetUserEditButton(TestUsers.TestHost.DisplayName).ClickNoWait();
            hostUserPage.UnauthorizeUserLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);

            //Assert
            Assert.IsTrue(hostUserPage.PopUpMessageSpan.Text.Contains("User successfully Un-Authorized"));
            hostUserPage.CancelLinkEditUserPage.Click();
            hostUserPage.UnauthorizedDisplayLink.ClickNoWait();
            Assert.IsTrue(hostUserPage.GetUserRow(TestUsers.TestHost.DisplayName).InnerHtml.Contains(TestUsers.TestHost.UserName));
        }

        [Test]
        [DependsOn("Unauthorize_Host_User")]
        public void Authorize_Host_User()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            HostUserPage hostUserPage = new HostUserPage(homePage);

            //Add Host User for Testing
            hostUserPage.AddUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password, TestUsers.TestHost.FirstName, TestUsers.TestHost.LastName, TestUsers.TestHost.EmailAddress, TestUsers.TestHost.DisplayName);
            System.Threading.Thread.Sleep(2000);
            
            //Unauthorize the host user
            hostUserPage.GetUserEditButton(TestUsers.TestHost.DisplayName).Click();
            hostUserPage.UnauthorizeUserLink.Click();
            ieInstance.GoTo(SiteURL + "/Home.aspx");

            //Act
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            hostUserPage.GetUserEditButton(TestUsers.TestHost.DisplayName).Click();
            hostUserPage.AuthorizeUserLink.Click();
            System.Threading.Thread.Sleep(2500);

            //Assert
            Assert.IsTrue(hostUserPage.PopUpMessageSpan.Text.Contains("User successfully Authorized"), hostUserPage.PopUpMessageSpan.Text);
            hostUserPage.CancelLinkEditUserPage.Click();
            hostUserPage.UnauthorizedDisplayLink.Click();
            Assert.IsNull(hostUserPage.GetUserRow(TestUsers.TestHost.DisplayName));
        }

        [Test]
        public void Update_Host_Password()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            HostUserPage hostUserPage = new HostUserPage(homePage);

            //Add Host User for Testing
            hostUserPage.AddUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password, TestUsers.TestHost.FirstName, TestUsers.TestHost.LastName, TestUsers.TestHost.EmailAddress, TestUsers.TestHost.DisplayName);
            System.Threading.Thread.Sleep(2000);
            
            //Act 
            hostUserPage.GetUserEditButton(TestUsers.TestHost.DisplayName).Click();
            System.Threading.Thread.Sleep(1500);
            hostUserPage.ManagePasswordLink.Click();
            hostUserPage.NewPasswordTextField.Value = TestUsers.TestHost.NewPassword;
            hostUserPage.ConfirmNewPasswordField.Value = TestUsers.TestHost.NewPassword;
            hostUserPage.ChangePasswordLink.ClickNoWait();
            
            //Assert
            Assert.IsTrue(hostUserPage.PopUpMessageSpan.Text.Contains("The password has been reset."));
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password);
            Assert.IsTrue(loginPage.LoginMessage.InnerHtml.Contains("Login Failed."));
        }

        [Test]
        public void Force_Password_Change()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            HostUserPage hostUserPage = new HostUserPage(homePage);

            //Add Host User for Testing
            hostUserPage.AddUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password, TestUsers.TestHost.FirstName, TestUsers.TestHost.LastName, TestUsers.TestHost.EmailAddress, TestUsers.TestHost.DisplayName);
            System.Threading.Thread.Sleep(2000);

            //Act 
            hostUserPage.GetUserEditButton(TestUsers.TestHost.DisplayName).ClickNoWait();
            hostUserPage.ForcePasswordChangeLink.ClickNoWait();
            System.Threading.Thread.Sleep(2500);

            //Assert
            Assert.IsTrue(hostUserPage.PopUpMessageSpan.Text.Contains("User must update password on next login"));
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            System.Threading.Thread.Sleep(2500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(2500);
            loginPage.LoginUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password);
            Assert.IsTrue(loginPage.RegisterLink.Text.StartsWith(TestUsers.TestHost.DisplayName));
        }

        [Test]
        public void Update_Profile_As_Host()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            HostUserPage hostUserPage = new HostUserPage(homePage);
            UserProfilePage profilePage = new UserProfilePage(homePage);

            //Add Host User for Testing
            hostUserPage.AddUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password, TestUsers.TestHost.FirstName, TestUsers.TestHost.LastName, TestUsers.TestHost.EmailAddress, TestUsers.TestHost.DisplayName);
            System.Threading.Thread.Sleep(2000);

            //Act 
            hostUserPage.GetUserEditButton(TestUsers.TestHost.DisplayName).ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            profilePage.ManageProfileLink.ClickNoWait();
            profilePage.UserStreetField.Value = "New Street";
            profilePage.ProfileUpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            System.Threading.Thread.Sleep(1500);
            TableCell userAddress = hostUserPage.GetUserRow(TestUsers.TestHost.DisplayName).TableCells[7];
            Assert.IsTrue(userAddress.Text.Contains("New Street"));
        }

        [Test]
        public void Update_Profile_As_Host_User()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            UserProfilePage profilePage = new UserProfilePage(homePage);
            HostUserPage hostUserPage = new HostUserPage(homePage);

            //Act
            homePage.RegisterLink.Click();
            System.Threading.Thread.Sleep(1500);
            profilePage.EditProfileLink.ClickNoWait();
            profilePage.UserStreetField.Value = "New Street";
            profilePage.ProfileUpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Assert
            homePage.RegisterLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(profilePage.ProfileStreetDiv.Text.Contains("New Street"));

            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            System.Threading.Thread.Sleep(2000);
            TableCell userAddress = hostUserPage.GetUserRow(TestUsers.Host.DisplayName).TableCells[7];
            Assert.IsTrue(userAddress.Text.Contains("New Street"));
        }

        [Test]
        public void Add_New_Visible_Profile_Feild()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            HostUserPage hostUserPage = new HostUserPage(homePage);
            

            //Add Host User for Testing
            hostUserPage.AddUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password, TestUsers.TestHost.FirstName, TestUsers.TestHost.LastName, TestUsers.TestHost.EmailAddress, TestUsers.TestHost.DisplayName);
            System.Threading.Thread.Sleep(2000);
            
            hostUserPage.ManageProfilePropertiesLink.Click();
            ProfilePropertiesPage propertiesPage = new ProfilePropertiesPage(homePage);

            //Act
            //Add Text Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "TextProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("349");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.LengthTextField.Value = "10";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow textPropertyRow = propertiesPage.GetPropertyRow("TextProperty");
            Assert.IsTrue(textPropertyRow.Exists);
            Assert.IsTrue(textPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[1]));
            TableCell textVisibilityCell = propertiesPage.GetPropertyVisibilityCell(textPropertyRow);
            Assert.IsTrue(textVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            //Add DateTime Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "DateTimeProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("360");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow dateTimePropertyRow = propertiesPage.GetPropertyRow("DateTimeProperty");
            Assert.IsTrue(dateTimePropertyRow.Exists);
            Assert.IsTrue(dateTimePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[2]));
            TableCell dateTimeVisibilityCell = propertiesPage.GetPropertyVisibilityCell(dateTimePropertyRow);
            Assert.IsTrue(dateTimeVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            //Add Country Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "CountryProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("356");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow countryPropertyRow = propertiesPage.GetPropertyRow("CountryProperty");
            Assert.IsTrue(countryPropertyRow.Exists);
            Assert.IsTrue(countryPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[3]));
            TableCell countryVisibilityCell = propertiesPage.GetPropertyVisibilityCell(countryPropertyRow);
            Assert.IsTrue(countryVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            //Add Region Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "RegionProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("357");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow regionPropertyRow = propertiesPage.GetPropertyRow("RegionProperty");
            Assert.IsTrue(regionPropertyRow.Exists);
            Assert.IsTrue(regionPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[4]));
            TableCell regionVisibilityCell = propertiesPage.GetPropertyVisibilityCell(regionPropertyRow);
            Assert.IsTrue(regionVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            //Add Image Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "ImageProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("361");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow imagePropertyRow = propertiesPage.GetPropertyRow("ImageProperty");
            Assert.IsTrue(imagePropertyRow.Exists);
            Assert.IsTrue(imagePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[5]));
            TableCell imageVisibilityCell = propertiesPage.GetPropertyVisibilityCell(imagePropertyRow);
            Assert.IsTrue(imageVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            //Assert
            //Check that the properties show up in the users profile correctly
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password);
            homePage.RegisterLink.Click();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.EditProfileLink.ClickNoWait();
            profilePage.ManageProfileLink.Click();
            //Enter Values for all the new properties
            profilePage.TextPropertyField.Value = "12345678910";
            profilePage.DateTimeDateField.Value = "04/05/2010";
            profilePage.HourSelectList.Select("08");
            profilePage.MinuteSelectList.Select("30");
            profilePage.AmPmSelectList.Select("PM");
            profilePage.CountryPropertySelectList.SelectByValue("Belgium");
            System.Threading.Thread.Sleep(2000);
            profilePage.RegionPropertyField.Value = "Test Region";
            profilePage.ImagePropertyUploadFileLink.ClickNoWait();
            profilePage.ImagePropertyFileUpload.Set(ImagePath);
            profilePage.ImagePropertySaveFileLink.Click();
            System.Threading.Thread.Sleep(1500);
            profilePage.ProfileUpdateLink.Click();
            System.Threading.Thread.Sleep(2000);
            //profilePage.EditProfileLink.Click();
            //profilePage.ManageProfileLink.Click();

            //Assert that they were save correctly.
            //Too many Characters were entered, the string should be shortened to "1234567891"
            Assert.IsTrue(profilePage.TextPropertyField.Text.CompareTo("1234567891") == 0);
            Assert.IsTrue(profilePage.DateTimeDateField.Text.CompareTo("4/5/2010") == 0);
            Assert.IsTrue(profilePage.HourSelectList.SelectedItem.CompareTo("08") == 0);
            Assert.IsTrue(profilePage.MinuteSelectList.SelectedItem.CompareTo("30") == 0);
            Assert.IsTrue(profilePage.AmPmSelectList.SelectedItem.CompareTo("PM") == 0);
            Assert.IsTrue(profilePage.CountryPropertySelectList.SelectedItem.CompareTo("Belgium") == 0);
            Assert.IsTrue(profilePage.RegionPropertyField.Text.CompareTo("Test Region") == 0);
            Assert.IsTrue(profilePage.FileSelectList.SelectedItem.CompareTo(ImageName) == 0);

        }

        [Test]
        public void Add_New_Invisible_Profile_Field()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            HostUserPage hostUserPage = new HostUserPage(homePage);


            //Add Host User for Testing
            hostUserPage.AddUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password, TestUsers.TestHost.FirstName, TestUsers.TestHost.LastName, TestUsers.TestHost.EmailAddress, TestUsers.TestHost.DisplayName);
            System.Threading.Thread.Sleep(2000);

            hostUserPage.ManageProfilePropertiesLink.Click();
            System.Threading.Thread.Sleep(1500);
            ProfilePropertiesPage propertiesPage = new ProfilePropertiesPage(homePage);

            //Act
            //Add Text Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "TextProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("349");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.LengthTextField.Value = "10";
            propertiesPage.VisibleCheckBox.Checked = false;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow textPropertyRow = propertiesPage.GetPropertyRow("TextProperty");
            Assert.IsTrue(textPropertyRow.Exists);
            Assert.IsTrue(textPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[1]));
            TableCell textVisibilityCell = propertiesPage.GetPropertyVisibilityCell(textPropertyRow);
            Assert.IsFalse(textVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            //Add DateTime Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "DateTimeProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("360");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = false;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow dateTimePropertyRow = propertiesPage.GetPropertyRow("DateTimeProperty");
            Assert.IsTrue(dateTimePropertyRow.Exists);
            Assert.IsTrue(dateTimePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[2]));
            TableCell dateTimeVisibilityCell = propertiesPage.GetPropertyVisibilityCell(dateTimePropertyRow);
            Assert.IsFalse(dateTimeVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            //Add Country Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "CountryProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("356");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = false;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow countryPropertyRow = propertiesPage.GetPropertyRow("CountryProperty");
            Assert.IsTrue(countryPropertyRow.Exists);
            Assert.IsTrue(countryPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[3]));
            TableCell countryVisibilityCell = propertiesPage.GetPropertyVisibilityCell(countryPropertyRow);
            Assert.IsFalse(countryVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            //Add Region Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "RegionProperty";
            propertiesPage.DataTypeSelectList.SelectByValue ("357");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.LengthTextField.Value = "10";
            propertiesPage.VisibleCheckBox.Checked = false;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow regionPropertyRow = propertiesPage.GetPropertyRow("RegionProperty");
            Assert.IsTrue(regionPropertyRow.Exists);
            Assert.IsTrue(regionPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[4]));
            TableCell regionVisibilityCell = propertiesPage.GetPropertyVisibilityCell(regionPropertyRow);
            Assert.IsFalse(regionVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            //Add Image Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "ImageProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("361");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = false;
            propertiesPage.NextButton.ClickNoWait();
            propertiesPage.ReturnToProfilePropertiesLink.ClickNoWait();
            //Check the property was added to the list before continuing 
            System.Threading.Thread.Sleep(1500);
            TableRow imagePropertyRow = propertiesPage.GetPropertyRow("ImageProperty");
            Assert.IsTrue(imagePropertyRow.Exists);
            Assert.IsTrue(imagePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[5]));
            TableCell imageVisibilityCell = propertiesPage.GetPropertyVisibilityCell(imagePropertyRow);
            Assert.IsFalse(imageVisibilityCell.CheckBox(Find.ById(s => s.Contains("ProfileDefinitions_grdProfileProperties"))).Checked);

            //Navigate to the SuperUser Accounts Page to assert that the properties are visible to the host
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            hostUserPage.GetUserEditButton(TestUsers.TestHost.DisplayName).ClickNoWait();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            
            profilePage.ManageProfileLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            //Assert
            Assert.IsTrue(profilePage.TextPropertyField.Exists);
            Assert.IsTrue(profilePage.DateTimeDateField.Exists);
            Assert.IsTrue(profilePage.HourSelectList.Exists);
            Assert.IsTrue(profilePage.MinuteSelectList.Exists);
            Assert.IsTrue(profilePage.AmPmSelectList.Exists);
            Assert.IsTrue(profilePage.CountryPropertySelectList.Exists);
            Assert.IsTrue(profilePage.RegionPropertyField.Exists);
            Assert.IsTrue(profilePage.ImageFileSelectList.Exists);

            //Navigate to the host users Profile Page 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password);
            homePage.RegisterLink.Click();
            profilePage.EditProfileLink.Click();
            System.Threading.Thread.Sleep(2000);

            //Assert
            Assert.IsFalse(profilePage.TextPropertyField.Exists);
            Assert.IsFalse(profilePage.DateTimeDateField.Exists);
            Assert.IsFalse(profilePage.HourSelectList.Exists);
            Assert.IsFalse(profilePage.MinuteSelectList.Exists);
            Assert.IsFalse(profilePage.AmPmSelectList.Exists);
            Assert.IsFalse(profilePage.CountryPropertySelectList.Exists);
            Assert.IsFalse(profilePage.RegionPropertyField.Exists);
            Assert.IsFalse(profilePage.ImageFolderSelectList.Exists);
            Assert.IsFalse(profilePage.FileUpload.Exists);
        }


        [Test]
        public void Delete_Host_User()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            //A user must first be added
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            HostUserPage hostUserPage = new HostUserPage(homePage);
            hostUserPage.AddUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password, TestUsers.TestHost.FirstName, TestUsers.TestHost.LastName, TestUsers.TestHost.EmailAddress, TestUsers.TestHost.DisplayName);
            System.Threading.Thread.Sleep(2000);
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();

            //Act 
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                hostUserPage.GetUserDeleteButton(TestUsers.TestHost.DisplayName).ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            System.Threading.Thread.Sleep(5000);

            //Assert
            Assert.IsTrue(hostUserPage.CheckUserDisplaysAsDeleted(TestUsers.TestHost.DisplayName));
            //Log the Host out 
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            //Attempt to login the deleted host user
            LoginPage userLoginPage = new LoginPage(homePage);
            userLoginPage.LoginUser(TestUsers.TestHost.UserName, TestUsers.TestHost.Password);
            Assert.IsTrue(userLoginPage.LoginMessage.InnerHtml.Contains("Login Failed."));
        }

         #endregion
    }
}
